package com.chan.service.impl;

import java.util.List;
import com.chan.common.core.domain.Ztree;
import com.chan.common.core.text.Convert;
import com.chan.common.utils.DateUtils;
import com.chan.service.ICdProgramService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chan.mapper.CdDocumentMapper;
import com.chan.domain.CdDocument;
import com.chan.service.ICdDocumentService;


/**
 * 文档库Service业务层处理
 *
 * @author chan
 * @date 2024-04-25
 */
@Service
public class CdDocumentServiceImpl implements ICdDocumentService
{
    @Autowired
    private CdDocumentMapper cdDocumentMapper;
    @Autowired
    private ICdProgramService cdProgramService;

    /**
     * 查询文档库
     *
     * @param id 文档库主键
     * @return 文档库
     */
    @Override
    public CdDocument selectCdDocumentById(Long id)
    {
        return cdDocumentMapper.selectCdDocumentById(id);
    }

    /**
     * 查询文档库列表
     *
     * @param cdDocument 文档库
     * @return 文档库
     */
    @Override
    public List<CdDocument> selectCdDocumentList(CdDocument cdDocument)
    {
        return cdDocumentMapper.selectCdDocumentList(cdDocument);
    }

    /**
     * 新增文档库
     *
     * @param cdDocument 文档库
     * @return 结果
     */
    @Override
    public int insertCdDocument(CdDocument cdDocument)
    {
        cdDocument.setCreateTime(DateUtils.getNowDate());
        return cdDocumentMapper.insertCdDocument(cdDocument);
    }

    /**
     * 修改文档库
     *
     * @param cdDocument 文档库
     * @return 结果
     */
    @Override
    public int updateCdDocument(CdDocument cdDocument)
    {
        cdDocument.setUpdateTime(DateUtils.getNowDate());
        return cdDocumentMapper.updateCdDocument(cdDocument);
    }

    /**
     * 批量删除文档库
     *
     * @param ids 需要删除的文档库主键
     * @return 结果
     */
    @Override
    public int deleteCdDocumentByIds(String ids)
    {
        return cdDocumentMapper.deleteCdDocumentByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除文档库信息
     *
     * @param id 文档库主键
     * @return 结果
     */
    @Override
    public int deleteCdDocumentById(Long id)
    {
        return cdDocumentMapper.deleteCdDocumentById(id);
    }

    @Override
    public List<Ztree> selectItemTree() {

        List<Ztree> ztrees = cdProgramService.selectCdProgramTree();

        return ztrees;
    }
}
